package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "移动端-复习模块")
@RestController
@RequestMapping("/user/review")
public class UserReviewController {

    private final UserReviewService userReviewService;

    public UserReviewController(UserReviewService userReviewService) {
        this.userReviewService = userReviewService;
    }

    // 1.APP端添加复习单词
    @PostMapping("voc")
    public Result addUserRovRev(@RequestBody List<Long> vocIds) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.addUserRovRev(vocIds, userId);
        return Result.ok();
    }

    // 2.同步APP端复习数据
    @PostMapping("data")
    public Result syncUserReviewData(@RequestBody UserReviewDataCommand command) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.synchronizeUserReviewData(command,userId);
        return Result.ok();
    }



    // 3.下载所有复习数据(首次登录时)
    @GetMapping("data")
    public Result downloadAllUserReviewData(PageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        DownLoadUserReviewDTO downLoadUserReviewDTO
                = userReviewService.downloadUserReviewData(pageRequest, userId);
        return Result.ok(downLoadUserReviewDTO);
    }


}
